<template>
	<view class="coupon">
		<view class="c-header">
			<text :class="index==0?'active':''" @click="changetab(0)">未使用({{count[0]}})</text>
			<text :class="index==2?'active':''" @click="changetab(2)">已使用({{count[2]}})</text>
			<text :class="index==3?'active':''" @click="changetab(3)">已作废({{count[3]}})</text>
		</view>

		<view class="content">
			<!-- 空白页 -->
			<view v-if="empty===true" class="empty">
				<image src="/static/img/1/5.png" mode="aspectFit"></image>

				<view class="empty-tips">无相关的优惠券</view>
			</view>

			<view v-else class="list">
				<view class="yes" v-if="index == 0">


					<view class="item" v-for="l in list" :key="l.couponCoding" @click="take(l)">
						<image src="/static/img/1/101.png" mode="aspectFit"></image>

						<view class="fit" :style="{background:l.backColor}">
							<!-- <image src="/static/img/1/2.png" mode="aspectFit" class="money"></image> -->
							<view class="info">
								<text class="titles">{{l.cEPName}}</text>
								<text class="money">￥{{l.reduceAmount}}</text>
							</view>
							<view class="info">
								<text class="title">满{{l.startAmount}}减{{l.reduceAmount}}</text>
								<text class="detail">{{l.iTypeName}}</text>
								<text class="detail">适用范围：{{l.scopeStr}}</text>
								<text class="detail">有效期至：{{l.expireEndDate}}</text>
							</view>
							<!-- <view class="circle">
								<view class="inner">
									<text class="text">去使用</text>
								</view>
								<view class="cover"></view>
							</view> -->
						</view>
					</view>

				</view>

				<view class="no" v-if="index == 2">
					<view class="item" v-for="l in list" :key="l.couponId">
						<image src="/static/img/1/19.png" mode="aspectFit"></image>
						<view class="fit">
							<view class="info">
								<text class="titles">{{l.cEPName}}</text>
								<text class="money">￥{{l.reduceAmount}}</text>
							</view>
							<view class="info">
								<text class="title">满{{l.startAmount}}减{{l.reduceAmount}}</text>
								<text class="detail">{{l.iTypeName}}</text>
								<text class="detail">适用范围：{{l.scopeStr}}</text>
								<text class="detail">有效期至：{{l.expireEndDate}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="no" v-if="index == 3">
					<view class="item" v-for="l in list" :key="l.couponId">
						<image src="/static/img/1/19.png" mode="aspectFit"></image>
						<view class="fit">
							<view class="info">
								<text class="titles">{{l.cEPName}}</text>
								<text class="money">￥{{l.reduceAmount}}</text>
							</view>
							<view class="info">
								<text class="title">满{{l.startAmount}}减{{l.reduceAmount}}</text>
								<text class="detail">{{l.iTypeName}}</text>
								<text class="detail">适用范围：{{l.scopeStr}}</text>
								<text class="detail">有效期至：{{l.expireEndDate}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				empty: false,
				index: 0,
				list: [],
				couponData: {},
				pageIndex:10,
				count:{
					0:0,
					1:0,
					2:0,
					3:0
				}
			}
		},
		async onLoad() {

			this.getData()
		},
		onReachBottom() {
			this.getData()
		},
		methods: {
			getData(){
				let postactivity = {
					orderBy: "reduceAmount",
					pageIndex: this.pageIndex,
					pageSize: 10,
					sequence: 1,
					status: this.index.toString()
				}
				
				this.$Request.post(this.$api.httpApi.user.getCouponList + "&token=" + this.$SysCache.get('token')+ "&iShopId=", 
					{"param":postactivity}
				).then(res => {
					
					if(res.data.count>this.list.length){
						this.list = this.list.concat(res.data.CouponUsage)
						this.pageIndex++
					}else{
						uni.showToast({
							title:"没有更多了！",
							icon:"none"
						})
					}
				
				})
				this.$Request.post(this.$api.httpApi.user.getCountCoupon + "&token=" + this.$SysCache.get('token'), {}).then(res => {
					this.count = res.data
				
				})
			},
			take(item){
				let data =  {"param":{"couponId":item.couponId}}
				this.$Request.post(this.$api.httpApi.user.sendCoupon + "&token=" + this.$SysCache.get('token'), data).then(res => {
					
				
				})
				
			},
			changetab(str) {
				this.list = []
				this.pageIndex = 1
				this.index = str
				this.getData()
			},
			toprepage(item) {
				this.$api.prePage().coupon = item;
				uni.navigateBack()
			}
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url: `/pages/coupon/explain`
			})
		}


	}
</script>

<style lang="scss">
	page {
		padding-bottom: 120upx;
		background: #f5f5f5;
	}

	.c-header {
		top: 44px;
		left: 0;
		right: 0;
		position: fixed;
		height: 80upx;
		padding: 20upx 70upx 0 70upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #000;
		z-index: 888;

		text {
			display: inline-flex;
			height: 100%;
			font-size: 25upx;
			font-family: Microsoft YaHei;
			font-weight: 400;
			color: #fff;
		}

		.active {
			color: #4DC897;
			border-bottom: 4upx solid #4DC897;
		}
	}

	.coupon {
		position: absolute;
		top: 44px;
		left: 0;
		right: 0;

		.empty {
			position: fixed;
			left: 0;
			top: 0;
			width: 100%;
			height: 100vh;
			padding-bottom: 173upx;
			display: flex;
			justify-content: center;
			flex-direction: column;
			align-items: center;

			image {
				width: 249upx;
				height: 248upx;
				margin-bottom: 10upx;
			}

			.empty-tips {
				display: flex;
				font-size: 31upx;
				font-family: Microsoft YaHei;
				font-weight: 400;
				color: rgba(102, 102, 102, 1);

			}
		}

		.list {
			padding: 23upx 21upx;

			.item {
				position: relative;
				margin-bottom: 21upx;
			}

			image {
				width: 100%;
				height: 200upx;
				display: block;
			}

			.fit {
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 25upx 45upx;

				.money {
					width: 180upx;
					height: 144upx;
				}

				.info {
					height: 100%;
					
					.titles{
						font-size: 24upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(255, 255, 255, 1);
						display: block;
						margin-top: 30upx;
					}
					.money{
						font-size: 50upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(255, 255, 255, 1);
					}
					.title {
						width: 200upx;
						height: 50upx;
						background: rgba(240, 64, 111, 0);
						border: 2upx solid rgba(255, 255, 255, 1);
						font-size: 27upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(255, 255, 255, 1);
						display: flex;
						justify-content: center;
						align-items: center;
						margin-bottom: 19upx;
					}

					.detail {
						display: flex;
						justify-content: flex-start;
						font-size: 19upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(255, 255, 255, 1);
						line-height: 30upx;
					}
				}

				.circle {
					width: 131upx;
					height: 131upx;
					position: relative;
					// background:rgba(255,255,255,1);
					// opacity:0.2;
					border-radius: 50%;
					display: flex;
					justify-content: center;
					align-items: center;

					.inner {
						width: 98upx;
						height: 98upx;
						background: rgba(4, 0, 0, 1);
						border-radius: 50%;
						display: flex;
						justify-content: center;
						align-items: center;
						z-index: 2;

						.text {
							font-size: 23upx;
							font-family: Microsoft YaHei;
							font-weight: 400;
							color: rgba(255, 255, 255, 1);
						}
					}

					.cover {
						position: absolute;
						top: 0;
						left: 0;
						right: 0;
						bottom: 0;
						background: rgba(255, 255, 255, 1);
						opacity: 0.2;
						border-radius: 50%;
						z-index: 1;
					}
				}
			}
		}
	}
</style>
